package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.dto.system.SysUserRoleDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.NamedBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Currency;
import java.util.List;

/**
 * @author MikeCoder
 * @create 2023-12-0511:53
 * @description:
 * @verson:
 */
@RestController
@RequestMapping(value = "/admin/system/sysUser")
@Tag(name = "用户管理接口",description = "用户管理相关的接口")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/getSysUserList/{current}/{limit}")
    @Operation(summary = "按分页条件展示数据",description = "按前端发送的分页参数，返回对应页的SysUser集合")
    @Parameters({@Parameter(name = "sysUserDto",description = "前端发送的搜索条件"),
            @Parameter(name ="current",description = "页码"),
            @Parameter(name = "limit",description = "每页显示的数据数量")})
    public Result<PageInfo<SysUser>> getSysUserList(@RequestBody SysUserDto sysUserDto,
                                                    @PathVariable Integer current,
                                                    @PathVariable Integer limit
    ){
        PageInfo<SysUser> sysUserList = sysUserService.getSysUserList(current,limit,sysUserDto);
        return Result.build(sysUserList, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/addSysUser")
    @Operation(summary = "添加SysUser接口",description = "添加一个SysUser对象")
    @Parameters(@Parameter(name = "sysUser",description = "前端传入的SysUser对象"))
    public Result addSysUser(@RequestBody SysUser sysUser){
        sysUserService.addSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/changeSysUser")
    @Operation(summary = "修改SysUser接口",description = "对指定id的SysUser对象进行修改")
    @Parameters(@Parameter(name = "sysUser",description = "前端传入的SysUser对象"))
    public Result changeSysUser(@RequestBody SysUser sysUser){
        sysUserService.changeSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/removeSysUser/{id}")
    @Operation(summary = "删除SysUser接口",description = "对指定id的SysUser对象进行删除")
    @Parameters(@Parameter(name = "id",description = "前端传入的SysUser对象id"))
    public Result removeSysUser(@PathVariable Integer id){
        sysUserService.remove(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "给用户分配角色")
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody SysUserRoleDto sysUserRoleDto){
        sysUserService.doAssign(sysUserRoleDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
